﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class Bordereau_Form_Modif_lot : Form
    {
       

        public modifierlotform Mlform = new modifierlotform();
        public List<Carte> Cartebordereau2 = new List<Carte>();
        Bordereau bordereauajoute = new Bordereau();
        public Bordereau_Form_Modif_lot()
        {
            InitializeComponent();  
            RAMEDEntities1 context = SingletonContext.GetContext();
            comboboxannexebordereau2.DataSource = context.Annexe_administratif;
            comboboxannexebordereau2.DisplayMember = "nom_annexe_administratif";
            comboboxannexebordereau2.ValueMember = "id_annexe_administratif";
          
        }

        private void Bordereau_form2_Load(object sender, EventArgs e)
        {

        }
        public void mettreAjourFormGridView()
        {
            dataGridViewbor2.DataSource = null;
            remplirDataGridView();
            dataGridViewbor2.Update();
            dataGridViewbor2.Refresh();
        }
        private void remplirDataGridView()
        {
            dataGridViewbor2.AutoGenerateColumns = false;
            dataGridViewbor2.ColumnCount = 5;
            dataGridViewbor2.Columns[0].HeaderText = "Nom";
            dataGridViewbor2.Columns[0].DataPropertyName = "Nom_benefi";

            dataGridViewbor2.Columns[1].HeaderText = "Prénom";
            dataGridViewbor2.Columns[1].DataPropertyName = "Prenom_benefi";

            dataGridViewbor2.Columns[2].HeaderText = "CIN";
            dataGridViewbor2.Columns[2].DataPropertyName = "CIN_benefi";

            dataGridViewbor2.Columns[3].HeaderText = "IPCM";
            dataGridViewbor2.Columns[3].DataPropertyName = "IPCM";

            dataGridViewbor2.Columns[4].HeaderText = "Centre de santé";
            dataGridViewbor2.Columns[4].DataPropertyName = "Centre_sante";

            dataGridViewbor2.DataSource = Cartebordereau2;
        }


    
        

        

        private void btnajouterbordereau_Click(object sender, EventArgs e)
        {
                
            }

        private void button3btnajoutercarte_Click(object sender, EventArgs e)
        {
            CarteForm2 CF2 = new CarteForm2();
            CF2.modifeirborderaeuForm = this;
            CF2.Show();
        }

        private void modifierButton2_Click(object sender, EventArgs e)
        {
            if (dataGridViewbor2.CurrentRow == null)
            {
                NotificationTest.NotificationManager nm = new NotificationTest.NotificationManager();
                nm.Show(this, "Veuillez sélectionner un carte pour le modifier", Color.Red, 3000);
            }
            else
            {
                ModifierCarte mbf2 = new ModifierCarte();

                Carte carte = new Carte();
                carte = ((Carte)dataGridViewbor2.CurrentRow.DataBoundItem);

                mbf2.Carte = carte;
                mbf2.InitialiserChamps();
                mbf2.bordereauFormModiflot = this;
                mbf2.Show();
            }
        }

        private void Bordereau_Form_Modif_lot_Load(object sender, EventArgs e)
        {

        }

        private void btnajouter2_Click(object sender, EventArgs e)
        {
            if(ValidateChildren(ValidationConstraints.Enabled))
            {

             RAMEDEntities1 Context = SingletonContext.GetContext();
            bordereauajoute.type_bordereau = txttypebordereau2.Text;
            bordereauajoute.Nombre_de_carte = utitlitaire.CasterString(txtnombrecarte2.Text);
            bordereauajoute.Annexe_administratif = ((Annexe_administratif)comboboxannexebordereau2.SelectedItem);

            foreach (Carte cart in Cartebordereau2)
                bordereauajoute.Cartes.Add(cart);

            Mlform.Lo.Bordereaux.Add(bordereauajoute);
            Mlform.mettreAjouterDataGridView1();

            this.Dispose();
            }
        }

        private void dataGridViewbor2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void txttypebordereau2_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Type est obligatoire", txttypebordereau2, e, errorProvider1);
        }

        private void txtnombrecarte2_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderNombre("Saisez un nombre valide", txtnombrecarte2, e, errorProvider1);
        }
        }
    }


